package navkakri;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Madhusudan
 */
public class Model {

static String m1="Turn of Player 1",m3="",m2="Player 1",m4="",m5="Player 2",m6="",m7="",m8="",m9="",m10="";
static int mouseX = 0,mouseY = 0;// coordinates of mouse
static int p1KukLeft=9,p2KukLeft=9;
static int turn=1,kc1=9,kc2=9,alreadyMadeCount=0;
static int nmodeflag=0;
static int outlined=100;
static boolean PutKukriMode=true,PickppKukMode=false,NormalMode=false;
static int spaces[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static int possibilities[][]={
    {1,7,-1,-1},//0
    {0,2,9,-1},//1
    {1,3,-1,-1},//2
    {2,4,11,-1},//3
    {3,5,-1,-1},//4
    {4,6,13,-1},//5
    {5,7,-1,-1},//6
    {0,6,15,-1},//7
    {9,15,-1,-1},//8
    {1,8,10,17},//9
    {9,11,-1,-1},//10
    {3,10,12,19},//11
    {11,13,-1,-1},//12
    {5,12,14,21},//13
    {13,15,-1,-1},//14
    {7,8,14,23},//15
    {17,23,-1,-1},//16
    {9,16,18,-1},//17
    {17,19,-1,-1},//18
    {11,18,20,-1},//19
    {19,21,-1,-1},//20
    {13,20,22,-1},//21
    {23,21,-1,-1},//22
    {15,16,22,-1}//23

};
static int AlreadyMade[][]={
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
};
static int Lines[][]={
    {0,1,2},//0
    {2,3,4},//1
    {4,5,6},//2
    {6,7,0},//3
    {8,9,10},//4
    {10,11,12},//5
    {12,13,14},//6
    {14,15,8},//7
    {16,17,18},//8
    {18,19,20},//9
    {20,21,22},//10
    {22,23,16},//11
    {1,9,17},//12
    {7,15,23},//13
    {5,13,21},//14
    {3,11,19},//15

};
static int RectCordinates[][]={
    {280,80,50,50},//0
    {670,80,50,50},//1
    {1070,80,50,50},//2
    {1070,375,50,50},//3
    {1070,675,50,50},//4
    {675,675,50,50},//5
    {280,675,50,50},//6
    {280,375,50,50},//7
    {375,180,50,50},//8
    {670,180,50,50},//9
    {970,180,50,50},//10
    {970,375,50,50},//11
    {970,575,50,50},//12
    {670,570,50,50},//13
    {375,570,50,50},//14
    {375,375,50,50},//15
    {475,275,50,50},//16
    {670,275,50,50},//17
    {870,275,50,50},//18
    {870,375,50,50},//19

    {870,475,50,50},//20
    {670,475,50,50},//21
    {475,475,50,50},//22
    {475,375,50,50},//23

};




  public static void changeTurn(){
    if(turn==1){
        turn=2;
        m1=" \nTurn of Player 2";
    }
    else{
        turn=1;
        m1="  \nTurn of Player 1";
    }
}
    public static void RemoveFromAlreadyMade(int turn,int click){
        for(int k=0;k<16;k++){
            if(AlreadyMade[k][0]==turn && (AlreadyMade[k][1]==click || AlreadyMade[k][2]==click || AlreadyMade[k][3]==click)){
                AlreadyMade[k][0]=0;
                AlreadyMade[k][1]=0;
                AlreadyMade[k][2]=0;
                AlreadyMade[k][3]=0;
                //JOptionPane.showMessageDialog(null, "Removed from Already MAde at Location = "+k);
                break;
            }
        }
    }

    public static int GetRectNo(int x,int y){
    int flag=-1;
    for(int i=0;i<24;i++){
        if(x >RectCordinates[i][0] && y >RectCordinates[i][1] && x<(RectCordinates[i][0]+50) && y <(RectCordinates[i][1]+50)){
                flag=i;
            }
    }
    return flag;
}

    public static int CheckIfKukriCanMove(int click){
        int flag=0;
        for(int k=0;k<4;k++){
            if(possibilities[click][k]!=-1){
                int c=possibilities[click][k];
                if(spaces[c]==0){
                    flag=1;
                }
            }
        }
        return flag;
    }
    public static int CheckLine(){
    int flag=0,flag2=0,l=0,lineNo=100,icount1=0,icount2=0;

        for(int i=0;i<16;i++){
            if(spaces[Lines[i][0]]==turn && spaces[Lines[i][1]]==turn && spaces[Lines[i][2]]==turn){
                flag=1;
                lineNo=i;
                icount1++;
              //  JOptionPane.showMessageDialog(null, "LineNo="+lineNo);
                System.out.println("icount1="+icount1);
                //  check if this line has already been counted or not
                for(int j=0;j<16;j++){
                    if(AlreadyMade[j][0]==turn && AlreadyMade[j][1]==Lines[i][0] && AlreadyMade[j][2]==Lines[i][1] && AlreadyMade[j][3]==Lines[i][2]){
                       // JOptionPane.showMessageDialog(null, "Already:="+AlreadyMade[j][0]+" "+AlreadyMade[j][1]+" "+AlreadyMade[j][2]+" "+AlreadyMade[j][3]);
                        icount2++;
                        flag2=1;
                    }
                }
                if(flag2==0 && lineNo!=100){
                    break;
                }
            }
        }
                if(icount1==icount2){
                    l=1;
                }
                //if line is not already counted then add to AlreadyMade
                if(l==0){
                    for(int k=0;k<16;k++){
                        if(AlreadyMade[k][0]==0 && AlreadyMade[k][0]==0 && AlreadyMade[k][0]==0 && AlreadyMade[k][0]==0){
                            alreadyMadeCount=k;
                            break;
                        }
                    }
                    AlreadyMade[alreadyMadeCount][0]=turn;
                    AlreadyMade[alreadyMadeCount][1]=Lines[lineNo][0];
                    AlreadyMade[alreadyMadeCount][2]=Lines[lineNo][1];
                    AlreadyMade[alreadyMadeCount][3]=Lines[lineNo][2];
                  //  JOptionPane.showMessageDialog(null, "Added to Already Made at location ="+alreadyMadeCount+"  "+AlreadyMade[alreadyMadeCount][1]+" "+AlreadyMade[alreadyMadeCount][2]);

                }

                if(flag==1 && l==0){
                return (1);
                }
                else{
                return (0);
                }
}
    public static int CheckIfKukriIsPArtOfLine(int click){
        int flag=0;
        for(int k=0;k<16;k++){
            if(AlreadyMade[k][1]==click || AlreadyMade[k][2]==click || AlreadyMade[k][3]==click ){
               flag=1;
             //  JOptionPane.showMessageDialog(null, "Founded at :"+AlreadyMade[k][1]);
               break;
            }
        }
        return flag;
    }
}
